<!-- 头部公用 -->
<template>
	<div>
		<div class="headBack " @scroll="handhandleScroll"
			:style="{ backgroundColor: `rgba(255, 255, 255, ${handgroundOpacity})`, color: `rgb(${handTextOpacity}, ${handTextOpacity}, ${handTextOpacity})` }">
			<el-row class="container1" v-if="isSidebarVisible">
				<el-col class="headcol1">
					<div style="position: relative;margin: 8px;font-size: 30px;font-family: Algerian">BYOND</div>
				</el-col>
				<el-col class="headcol2">
					<!-- pc端导航 -->
					<div class="headBox">
						<el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal"
							@select="handleSelect" :router="true" background-color="inherit" text-color="inherit"
							active-text-color="#ffd04b">
							<el-menu-item index="/"><i class="el-icon-s-comment"
									style="color: inherit;"></i>主页</el-menu-item>
							<el-submenu index="/Share" text-color="inherit">
								<template slot="title"><i class="fa fa-wa fa-archive" style="color: inherit"></i>
									分类</template>
								<el-menu-item v-for="(item, index) in classListObj" :key="'class1' + index"
									:index="'/Share?classId=' + item.id" background-color="inherit">{{ item.name
									}}</el-menu-item>
							</el-submenu>
							<el-menu-item style="color: inherit;" index="/Message"><i class="el-icon-s-comment"
									style="color: inherit"></i>留言</el-menu-item>
							<el-menu-item index="/record" style="color: inherit"><i class="el-icon-s-promotion"
									style="color: inherit"></i>记录</el-menu-item>
							<el-menu-item index="/music" style="color: inherit"><i class="el-icon-s-shop"
									style="color: inherit"></i>百宝箱</el-menu-item>
							<el-menu-item index="/Photo" style="color: inherit"><i class="el-icon-picture"
									style="color: inherit"></i>
								相片</el-menu-item>
							<el-menu-item index="/Friendslink" style="color: inherit"><i class="fa fa-wa fa-users"
									style="color: inherit"></i>友链</el-menu-item>
							<el-menu-item style="color: inherit"><i class="fa fa-wa fa-users"
									style="color: inherit"></i><a href="http://czhlxy.icu:9988">后台</a></el-menu-item>
						</el-menu>
					</div>
				</el-col>
				<el-col class="headcol3">
					<div class="userInfo" style="color: initial;">

						<div v-show="!haslogin" class="nologin">
							<a style="font-size: 15px;" href="javascript:void(0);" @click="logoinFun(1)"
								:style="{ color: `rgb(${handTextOpacity}, ${handTextOpacity}, ${handTextOpacity})` }">登录&nbsp;&nbsp;|</a>
							<a href="javascript:void(0);" @click="logoinFun(0)" style="font-size: 15px"
								:style="{ color: `rgb(${handTextOpacity}, ${handTextOpacity}, ${handTextOpacity})` }">注册</a>
						</div>

						<div v-show="haslogin" class="haslogin">
							<el-dropdown style="margin: 10px;">
								<span class="el-dropdown-link">
									<i class="fa fa-fw fa-user-circle userImg"></i>
								</span>
								<el-dropdown-menu slot="dropdown">
									<el-dropdown-item>
										<a style="font-size: 15px" href="#/UserInfo">个人中心</a>
									</el-dropdown-item>
									<el-dropdown-item>
										<a style="font-size: 15px" href="javascript:void(0);"
											@click="userlogout">退出登录</a>
									</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>

						</div>
					</div>
				</el-col>
			</el-row>
			<!-- 导航栏折叠手机端导航 -->
			<el-row v-show="!isSidebarVisible && !phoneNavVisible">
				<el-col :span="21">
					<div style="position: relative;margin: 15px;font-size: 30px;font-family: Algerian;">BYOND
					</div>
				</el-col>
				<el-col :span="3">
					<i class="el-icon-s-operation" style="font-size: 30px;margin: 15px;" @click="phoneNav()"></i>
				</el-col>
			</el-row>
			<div class="phoneNavclass" :class="{ 'show-nav': phoneNavVisible }">
				<ul class="ul1":class="{'show-nav1':phoneNavVisible}">
					<li><router-link to="/" style="color: white;">🏡&nbsp;主页 <i
								class="el-icon-loading"></i></router-link></li>
					<li>📒&nbsp;分类</li>
					<ul class="ul2">
						<li v-for="(item, index) in classListObj" :key="'class1' + index">
							<router-link :to="'/Share?classId=' + item.id" style="color: white;">💠{{ item.name
								}}</router-link>
						</li>
					</ul>
					<li><router-link to="/Message" style="color: white;">📪&nbsp;留言</router-link></li>
					<li><router-link to="/record" style="color: white;">🌏&nbsp;记录</router-link></li>
					<li><router-link to="/music" style="color: white;">🎀&nbsp;百宝箱</router-link></li>
					<li><router-link to="/Photo" style="color: white;">📷&nbsp;照片</router-link></li>
					<li><router-link to="/Friendslink" style="color: white;">💬&nbsp;友链</router-link></li>
					<li><a href="http://czhlxy.icu:9988" style="color: white;">💻&nbsp;后台</a></li>
					<li v-if="!haslogin"><router-link to="/Login?login=1" style="color: white;">💖&nbsp;登录</router-link></li>
					<li v-else><router-link to="/UserInfo" style="color: white;">📋&nbsp;个人中心</router-link></li>
					<li v-if="haslogin" @click="userlogout">📲&nbsp;退出登录</li>
				</ul>
			</div>
			<div v-if="phoneNavVisible" class="phoneNav1" @click="noNav()">
				<!-- 遮罩 -->
			</div>
		</div>
	</div>
</template>
<script>
import { logout } from '../api/user'
import { removeToken } from '../utils/auth'
import { getCategoryList } from '../api/category'
import { Typeit } from '../utils/plug.js'

export default {
	data() { //选项 / 数据
		return {
			userInfo: '', //用户信息
			haslogin: false, //是否已登录
			classListObj: '', //分类
			activeIndex: '/', //当前选择的路由模块
			// path:'',//当前打开页面的路径
			input: '', //input输入内容
			handgroundOpacity: 0, // 导航栏背景透明度，初始为完全透明  
			handscrollPosition: 0, // 当前滚动位置  
			handscrollThreshold: 510, // 滚动阈值，当滚动超过这个值时开始改变透明度  
			handTextOpacity: 255,
			isSidebarVisible: true,
			phoneNavVisible: false,

		}
	},
	computed: {
	},
	methods: {
		//关闭手机端右遮罩层
		noNav() {
			this.phoneNavVisible = false
		},
		//获取滚动条位置
		handhandleScroll(event) {
			this.handscrollPosition = window.scrollY || window.pageYOffset || document.body.scrollTop + (document.documentElement && document.documentElement.scrollTop || 0);
			this.updateNavBackground();
		},
		//导航栏背景透明度
		updateNavBackground() {
			const opacity = Math.max(0, this.handscrollPosition / this.handscrollThreshold);
			this.handgroundOpacity = opacity;
			this.handTextOpacity = 255 - opacity * 255;
		},
		handleOpen(key, keyPath) { //分组菜单打开
			// console.log(key, keyPath);
		},
		handleClose(key, keyPath) { //分组菜单关闭
			// console.log(key, keyPath);
		},
		searchChangeFun(e) { //input change 事件
			// console.log(e)
			if (this.input == '') {
				this.$store.state.keywords = '';
				this.$router.push({ path: '/' });
			}
		},
		//请求分类
		getCategoryList() {
			getCategoryList().then((response) => {
				this.classListObj = response
			})
		},
		handleSelect(key, keyPath) { //pc菜单选择
			//    console.log(key, keyPath);
		},
		logoinFun: function (msg) { //用户登录和注册跳转
			// console.log(msg);
			localStorage.setItem('logUrl', this.$route.fullPath);
			// console.log(666,this.$router.currentRoute.fullPath);
			if (msg == 0) {
				this.$router.push({
					path: '/Login?login=0'
				});
			} else {
				this.$router.push({
					path: '/Login?login=1'
				});
			}
		},
		// 用户退出登录
		userlogout: function () {
			var that = this;
			this.$confirm('是否确认退出?', '退出提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				// console.log(that.$route.path);

				logout().then((response) => {
					removeToken()
					localStorage.removeItem('userInfo');
					that.haslogin = false;
					window.location.reload();
					that.$message({
						type: 'success',
						message: '退出成功!'
					});
					if (that.$route.path == '/UserInfo') {
						that.$router.push({
							path: '/'
						});
					}
				})
			}).catch(() => {
				//
			});

		},
		//路由变化
		routeChange: function () {
			var that = this;
			that.pMenu = true
			this.activeIndex = this.$route.path == '/' ? '/Home' : this.$route.path;
			if (localStorage.getItem('userInfo')) { //存储用户信息
				that.haslogin = true;
				that.userInfo = JSON.parse(localStorage.getItem('userInfo'));
				// console.log(that.userInfo);
			} else {
				that.haslogin = false;
			}
			//获取分类
			this.getCategoryList()

			if ((this.$route.name == "Share" || this.$route.name == "Home") && this.$store.state.keywords) {
				this.input = this.$store.state.keywords;
			} else {
				this.input = '';
				this.$store.state.keywords = '';
			};
		},
		//关闭手机端导航栏
		phoneNav() {
			this.phoneNavVisible = !this.phoneNavVisible
		},
		handleOutsideClick(event) {
			// 如果点击事件的目标不是导航栏本身，也不是导航栏内部的任何元素，则隐藏导航栏  
			// if (this.$refs.noNav != (event.target)) {
			// 	this.phoneNavVisible = false;
			// }
		},

	},
	watch: {
		// 如果路由有变化，会再次执行该方法
		'$route': 'routeChange'
	},
	created() { //生命周期函数
		//判断当前页面是否被隐藏
		var that = this;
		var hiddenProperty = 'hidden' in document ? 'hidden' :
			'webkitHidden' in document ? 'webkitHidden' :
				'mozHidden' in document ? 'mozHidden' :
					null;
		var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
		var onVisibilityChange = function () {
			if (!document[hiddenProperty]) { //被隐藏
				if (that.$route.path != '/DetailShare') {
					if (localStorage.getItem('userInfo')) {
						that.haslogin = true;
					} else {
						that.haslogin = false;
					}
				}
			}
		}
		document.addEventListener(visibilityChangeEvent, onVisibilityChange);
		// console.log();
		this.routeChange();

	},
	mounted() { //页面元素加载完成
		var that = this;
		var timer = setTimeout(function () {
			Typeit(that.$store.state.themeObj.user_start, "#luke"); //打字机效果
			clearTimeout(timer);
		}, 500);
		window.addEventListener('scroll', this.handhandleScroll);
		if (window.innerWidth < 1280) {
			this.isSidebarVisible = false
		};
		// document.addEventListener('mousedown', this.handleOutsideClick);
	},
	//清除计数器，防止内存泄漏
	beforeDestroy() {
		window.removeEventListener('scroll', this.handhandleScroll);
		// document.removeEventListener('mousedown', this.handleOutsideClick);
	},
}
</script>

<style>
/*********头部导航栏********/

/*头部导航栏盒子*/
.container1 {
	width: 100%;
	margin-left: 5%;
	margin-right: 5%;
}

.userImg {
	font-size: 35px;
	margin: 0 auto
}

.headBack {
	width: 100%;
	background: rgba(40, 42, 44, 0.6);
	/*margin-bottom:30px;*/
	box-shadow: 0 2px 4px 0 rgba(0, 0, 0, .12), 0 0 6px 0 rgba(0, 0, 0, .04);
	position: fixed;
	left: 0;
	top: 0;
	right: 0;
	z-index: 100;
	font-family: 'NavbarFont';

}

.headBox {
	margin: 8px;
}

.jiantou {
	width: 100%;
	position: relative;
	top: 500px;

}

.jiantou img {
	width: 50px;
	margin: 0 50%
}

.headBox li.is-active {
	/*background: #48456C;*/
	background: rgba(73, 69, 107, 0.7);
}

.el-menu--horizontal>.el-submenu.is-active .el-submenu__title {
	border-bottom: none !important;
}

.headBox .el-menu {
	background: transparent;
	border-bottom: none !important;
	font-size: 36px;
}

.headBox .el-menu-demo li.el-menu-item,
.headBox .el-menu--horizontal .el-submenu .el-submenu__title {
	height: 38px;
	line-height: 38px;
	border-bottom: none !important;
	font-size: 20px;

}

.headBox .el-submenu .el-menu-item {
	height: 38px;
	line-height: 38px;
}

.headBox li .fa-wa {
	vertical-align: baseline;
}

/* .headBox ul li.el-menu-item,
.headBox ul li.el-menu-item.is-active,
.headBox ul li.el-menu-item:hover,
.headBox .el-submenu div.el-submenu__title,
.headBox .el-submenu__title i.el-submenu__icon-arrow {
	color: #fff;
} */

.headBox .el-menu--horizontal .el-submenu>.el-menu {
	top: 38px;
	border: none;
	padding: 0;
}

.headBox>ul li.el-menu-item:hover,
.headBox>ul li.el-submenu:hover .el-submenu__title {
	background: #48456C;
	border-bottom: none;
}

.headBox>ul .el-submenu .el-menu,
.headBox>ul .el-submenu .el-menu .el-menu-item {
	background: #48456C;

}

.headBox>ul .el-submenu .el-menu .el-menu-item {
	min-width: 0;
}

.headBox>ul .el-submenu .el-menu .el-menu-item:hover {
	background: #64609E;
}

/*pc搜索框*/

.headBox .pcsearchbox {
	padding: 0;
	max-width: 170px;
	/*min-width: 30px;*/
	height: 100%;
	line-height: 38px;
	position: absolute;
	top: 0;
	right: 0;
	cursor: pointer;
}

.headBox .pcsearchbox:hover .pcsearchinput {
	opacity: 1;
	/*transform: scaleX(1);*/
	visibility: visible;
}

.headBox .pcsearchbox i.pcsearchicon {
	color: #fff;
	padding-left: 10px;
}

.headBox .pcsearchbox .pcsearchinput {
	width: 180px;
	padding: 10px 20px 10px 20px;
	background: rgba(40, 42, 44, 0.6);
	border-radius: 0 0 2px 2px;
	position: absolute;
	right: 0;
	top: 38px;
	opacity: 0;
	visibility: hidden;
	/*transform: scaleX(0);*/
	transform-origin: right;
	transition: all 0.3s ease-out;
}

.headBox .pcsearchbox .hasSearched {
	opacity: 1;
	/*transform: scaleX(1);*/
	visibility: visible;
}

.headBox .pcsearchbox .el-input {
	width: 100%;
}

.headBox .el-input__inner {
	height: 30px;
	border: none;
	background: #fff;
	/*border: 1px solid #333;*/
	border-radius: 2px;
	padding-right: 10px;
}

.userInfo {
	font-size: 30px;
	/* color: #fff; */
}

.headBox .userInfo a {
	color: #fff;
	transition: all 0.2s ease-out;
}

.headBox .userInfo a:hover {
	color: #48456C;
}

.headBox .nologin {
	text-align: right;
}

.headBox .haslogin {
	text-align: right;
	position: relative;
	min-width: 80px;
	cursor: pointer;
}

.headBox .haslogin:hover ul {
	visibility: visible;
	opacity: 1;
}

.headBox .haslogin ul {
	background: rgba(40, 42, 44, 0.6);
	padding: 5px 10px;
	position: absolute;
	right: 0;
	visibility: hidden;
	opacity: 0;
	transition: all 0.3s ease-out;
}

.headBox .haslogin ul li {
	border-bottom: 1px solid #48456C;
}

.headBox .haslogin ul li:last-child {
	border-bottom: 1px solid transparent;
}

/*******移动端*******/
.phoneNavclass {
	position: fixed;
	top: 0;
	left: 0;
	height: 100vh;
	background-image: url('../../static/img/sidbar.jpg');
	background-size: cover;
	background-position: center top;
	background-repeat: no-repeat;
	transition: all 0.5s ease-in-out;
	box-shadow: #000000 0 0 15px;
	border-top-right-radius: 50px;
	border-bottom-right-radius: 50px;
	z-index: 999;
	width: 0;
}

.phoneNavclass.show-nav {
	width: 55%;
}

.phoneNav1 {
	width: 100%;
	height: 100%;
	position: fixed;
	top: 0;
	left: 0;
	background: rgba(0, 0, 0, 0.5);
}

.mask {
	position: fixed;
	top: 0;
	right: 0;
	height: 100%;
	background: rgba(0, 0, 0, 0.5);
}

.ul1 {
	width: 60%;
	margin: 0 auto;
	margin-top: 50px;
	text-align: left;
	font-size: 20px;
	line-height: 50px;
	color: #fff;
	position: relative;
	left: -100vw;
	transition: all 0.5s ease-in-out;
}
.show-nav1{
	left: 0;
}
.ul2 {
	width: 100%;
	position: flex;
	margin: 0 auto;
	font-size: 15px;
	text-align: center;
}

.mobileBox {
	position: relative;
	height: 38px;
	line-height: 38px;
	/* color: #fff; */
}

.hideMenu {
	position: relative;
	width: 100%;
	height: 100%;
	line-height: 38px;
}

.hideMenu ul.mlistmenu {
	width: 100%;
	position: absolute;
	left: 0;
	top: 100%;
	box-sizing: border-box;
	z-index: 999;
	box-shadow: 0 2px 6px 0 rgba(0, 0, 0, .12), 0 0 8px 0 rgba(0, 0, 0, .04);
	background: #48456C;
	color: #fff;
	border-right: none;
}

.hideMenu .el-submenu .el-menu {
	background: #64609E;
}

.hideMenu .el-menu-item,
.hideMenu .el-submenu__title {
	color: #fff;
}

.hideMenu>i {
	position: absolute;
	left: 10px;
	top: 12px;
	width: 30px;
	height: 30px;
	font-size: 16px;
	/* color: #fff; */
	cursor: pointer;
}

.hideMenu .el-menu-item,
.el-submenu__title {
	height: 40px;
	line-height: 40px;
}

.mobileBox .searchBox {
	padding-left: 40px;
	width: 100%;
	box-sizing: border-box;
}

.mobileBox .searchBox .el-input__inner {
	display: block;
	border-radius: 2px;
	border: none;
	height: 25px;
}

.hideMenu ul.mlistmenu.pshow {
	display: block;
}

/* .hideMenu ul.mlistmenu .el-submenu__icon-arrow,
.mobileBox li.el-menu-item a {
	color: #fff;
} */

.hideMenu>ul li.el-menu-item:hover,
.hideMenu>ul li.el-menu-item.is-active {
	background: #48576a;
}



/*头部背景图*/



.h-information {
	height: 4rem;
	text-align: center;
	width: 70%;
	margin: auto;
	position: relative;
	top: 500px;
	padding: 40px 0;
	font-size: 16px;
	opacity: 0.98;
	background: rgba(222, 255, 254, 0.468);
	border-radius: 5px;
	z-index: 0;
	animation: b 1s ease-out;
	-webkit-animation: b 1s ease-out;
}

@-webkit-keyframes b {
	0% {
		-webkit-transform: translateY(90px);
		transform: translateY(90px);
	}

	80% {
		-webkit-transform: translateY(5px);
		transform: translateY(5px)
	}

	90% {
		-webkit-transform: translateY(-5px);
		transform: translateY(-5px)
	}

	to {
		-webkit-transform: translateY(0);
		transform: translateY(0)
	}
}

@keyframes b {
	0% {
		-webkit-transform: translateY(90px);
		transform: translateY(90px);
	}

	80% {
		-webkit-transform: translateY(5px);
		transform: translateY(5px)
	}

	90% {
		-webkit-transform: translateY(-5px);
		transform: translateY(-5px)
	}

	to {
		-webkit-transform: translateY(0);
		transform: translateY(0)
	}
}



.h-information h2 {
	color: #fff;
	font-family: 'keaiFont' !important;
	margin-top: 20px;
	font-size: 28px;
	font-weight: 700;
	/* font-family: 'Sigmar One'; */
}

.h-information h2 a {
	background: linear-gradient(to right, #DF2050, #48456D);
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
}





.saying:after {
	content: "|";
	font-family: Arial, sans-serif;
	font-size: 1em;
	/*line-height: 0;*/
	display: inline-block;
	vertical-align: baseline;
	opacity: 1;
	text-shadow: 1px 1px 0 #ff3f1a, -1px -1px 0 #00a7e0;
	animation: caret 500ms infinite;
}

@keyframes caret {

	0%,
	100% {
		opacity: 1;
	}

	50% {
		opacity: 0;
	}
}
</style>
